Skip to main content

Linux File Management Commands

๐Ÿš€ vi, nano, touch, and cat Commands

โœจ vi (Visual Editor)โ€‹

vi is a powerful text editor available in Unix/Linux systems. It has two main modes:

  • ๐Ÿ”น Command mode: Used for navigation and issuing commands.
  • ๐Ÿ“ Insert mode: Used for editing text.

๐Ÿ”ฅ Basic Commands:โ€‹

  • vi filename โ†’ ๐Ÿ—๏ธ Open or create a file.
  • Press i โ†’ โœ๏ธ Switch to insert mode.
  • Press Esc โ†’ ๐Ÿ”™ Switch to command mode.
  • :w โ†’ ๐Ÿ’พ Save file.
  • :q โ†’ ๐Ÿšช Quit.
  • :wq or ZZ โ†’ โœ… Save and quit.
  • :q! โ†’ โŒ Quit without saving.

๐Ÿ–Š๏ธ nano (Simple Text Editor)โ€‹

nano is a user-friendly text editor with on-screen navigation.

๐Ÿ”ฅ Basic Commands:โ€‹

  • nano filename โ†’ ๐Ÿ—๏ธ Open or create a file.
  • CTRL + X โ†’ ๐Ÿšช Exit.
  • CTRL + O โ†’ ๐Ÿ’พ Save file.
  • CTRL + W โ†’ ๐Ÿ” Search.
  • CTRL + K โ†’ โœ‚๏ธ Cut a line.
  • CTRL + U โ†’ ๐Ÿ“‹ Paste a line.

๐Ÿ“ touch (Create Empty Files)โ€‹

The touch command is used to create an empty file or update the timestamp of an existing file.

๐Ÿ”ฅ Usage:โ€‹

  • touch filename โ†’ ๐Ÿ“‚ Create a new empty file.
  • touch file1 file2 โ†’ ๐Ÿ“‚๐Ÿ“‚ Create multiple empty files.
  • touch -t YYYYMMDDHHMM filename โ†’ โณ Change file timestamp.

๐Ÿ“œ cat (Concatenate and View Files)โ€‹

cat is used to display, concatenate, and create files.

๐Ÿ”ฅ Usage:โ€‹

  • cat filename โ†’ ๐Ÿ“– Display file content.
  • cat file1 file2 โ†’ ๐Ÿ”— Concatenate and display multiple files.
  • cat > filename โ†’ ๐Ÿ“ Create a new file and enter content.
  • cat filename1 >> filename2 โ†’ โž• Append content of one file to another.

๐Ÿ” Differences Between vi, nano, touch, and catโ€‹

๐Ÿ› ๏ธ Command๐ŸŽฏ Purpose
๐Ÿ–ฅ๏ธ viAdvanced text editor with modes and commands.
โœ๏ธ nanoSimple, user-friendly text editor.
๐Ÿ“ touchCreates an empty file or updates timestamps.
๐Ÿ“œ catDisplays, concatenates, and creates files.

These commands are essential for working with files in Linux and are commonly used in system administration and development workflows.


โšก Advanced Commandsโ€‹

โš™๏ธ Command๐Ÿ† Function
๐Ÿ–ฅ๏ธ vi
/search_term๐Ÿ” Search for a term in the file.
nโญ๏ธ Jump to the next occurrence of the search term.
Nโฎ๏ธ Jump to the previous occurrence of the search term.
:%s/old/new/g๐Ÿ”„ Replace all occurrences of 'old' with 'new'.
:set nu๐Ÿ”ข Show line numbers.
โœ๏ธ nano
CTRL + W๐Ÿ”Ž Search for a term.
CTRL + R๐Ÿ”„ Replace text.
CTRL + _๐ŸŽฏ Jump to a specific line.
ALT + Uโช Undo last action.
ALT + E๐Ÿ”„ Enable/Disable smooth scrolling.
๐Ÿ“ touch
touch -c filename๐Ÿšซ Do not create a file if it doesnโ€™t exist.
touch -a filenameโณ Update only the access time.
touch -m filenameโณ Update only the modification time.
touch -d 'YYYY-MM-DD HH:MM:SS' filenameโฐ Set a specific timestamp.
๐Ÿ“œ cat
cat -n filename๐Ÿ”ข Display file content with line numbers.
cat -s filename๐Ÿšซ Suppress repeated empty lines.
cat -A filename๐Ÿ•ต๏ธ Show all hidden characters.
cat < file1 > file2๐Ÿ”€ Redirect contents of file1 to file2.

๐ŸŽ‰ Hope this helps in mastering these commands! ๐Ÿš€